import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * staticTextOrg.js
 * @date 2018-12-25

 */
import { createPagination, getResponse } from 'utils/utils';
import { staticTextCreateOne, staticTextFetchList, staticTextFetchOne, staticTextRemoveList, staticTextUpdateOne } from "../services/staticTextOrgService";
export default {
  namespace: 'staticTextOrg',
  state: {
    lov: {},
    // 存放值集
    list: {},
    // 存放 list 页面信息
    detail: {} // 存放 detail 页面信息

  },
  effects: {
    fetchStaticTextList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchStaticTextList(_ref, _ref2) {
      var payload, call, put, organizationId, params, res, staticTextList;
      return _regeneratorRuntime.wrap(function fetchStaticTextList$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              organizationId = payload.organizationId, params = payload.params;
              _context.next = 5;
              return call(staticTextFetchList, organizationId, params);

            case 5:
              res = _context.sent;
              staticTextList = getResponse(res);

              if (!staticTextList) {
                _context.next = 10;
                break;
              }

              _context.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  list: {
                    dataSource: staticTextList.content,
                    pagination: createPagination(staticTextList)
                  }
                }
              });

            case 10:
              return _context.abrupt("return", staticTextList);

            case 11:
            case "end":
              return _context.stop();
          }
        }
      }, fetchStaticTextList);
    }),
    fetchStaticTextOne: /*#__PURE__*/_regeneratorRuntime.mark(function fetchStaticTextOne(_ref3, _ref4) {
      var payload, call, put, organizationId, textId, params, res, staticTextDetail;
      return _regeneratorRuntime.wrap(function fetchStaticTextOne$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call, put = _ref4.put;
              organizationId = payload.organizationId, textId = payload.textId, params = payload.params;
              _context2.next = 5;
              return call(staticTextFetchOne, organizationId, textId, params);

            case 5:
              res = _context2.sent;
              staticTextDetail = getResponse(res);

              if (!staticTextDetail) {
                _context2.next = 10;
                break;
              }

              _context2.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  detail: {
                    record: staticTextDetail
                  }
                }
              });

            case 10:
            case "end":
              return _context2.stop();
          }
        }
      }, fetchStaticTextOne);
    }),
    removeStaticTextList: /*#__PURE__*/_regeneratorRuntime.mark(function removeStaticTextList(_ref5, _ref6) {
      var payload, call, organizationId, params, res;
      return _regeneratorRuntime.wrap(function removeStaticTextList$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call;
              organizationId = payload.organizationId, params = payload.params;
              _context3.next = 5;
              return call(staticTextRemoveList, organizationId, params);

            case 5:
              res = _context3.sent;
              return _context3.abrupt("return", getResponse(res));

            case 7:
            case "end":
              return _context3.stop();
          }
        }
      }, removeStaticTextList);
    }),
    removeStaticTextOne: /*#__PURE__*/_regeneratorRuntime.mark(function removeStaticTextOne(_ref7, _ref8) {
      var payload, call, organizationId, params, res;
      return _regeneratorRuntime.wrap(function removeStaticTextOne$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref7.payload;
              call = _ref8.call;
              organizationId = payload.organizationId, params = payload.params;
              _context4.next = 5;
              return call(staticTextRemoveList, organizationId, params);

            case 5:
              res = _context4.sent;
              return _context4.abrupt("return", getResponse(res));

            case 7:
            case "end":
              return _context4.stop();
          }
        }
      }, removeStaticTextOne);
    }),
    updateStaticTextOne: /*#__PURE__*/_regeneratorRuntime.mark(function updateStaticTextOne(_ref9, _ref10) {
      var payload, call, organizationId, params, res;
      return _regeneratorRuntime.wrap(function updateStaticTextOne$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref9.payload;
              call = _ref10.call;
              organizationId = payload.organizationId, params = payload.params;
              _context5.next = 5;
              return call(staticTextUpdateOne, organizationId, params);

            case 5:
              res = _context5.sent;
              return _context5.abrupt("return", getResponse(res));

            case 7:
            case "end":
              return _context5.stop();
          }
        }
      }, updateStaticTextOne);
    }),
    createStaticTextOne: /*#__PURE__*/_regeneratorRuntime.mark(function createStaticTextOne(_ref11, _ref12) {
      var payload, call, organizationId, params, res;
      return _regeneratorRuntime.wrap(function createStaticTextOne$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref11.payload;
              call = _ref12.call;
              organizationId = payload.organizationId, params = payload.params;
              _context6.next = 5;
              return call(staticTextCreateOne, organizationId, params);

            case 5:
              res = _context6.sent;
              return _context6.abrupt("return", getResponse(res));

            case 7:
            case "end":
              return _context6.stop();
          }
        }
      }, createStaticTextOne);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref13) {
      var payload = _ref13.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    },
    clearDetail: function clearDetail(state) {
      return _objectSpread(_objectSpread({}, state), {}, {
        detail: {}
      });
    }
  }
};